﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

    <title>jb-aptech毕业设计项目</TITLE>
    <meta name="renderer" content="ie-comp">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="../../css/menu.css">

    <script src="../../script/jquery-3.3.1.min.js"></script>
    <script src="../../script/common.js"></script>
    <script src="../../../js/bootstrap.min.js"></script>
    <script src="../../../js/vue.js"></script>
</head>
<body>
<div id="query">
<div class="page_title">权限管理 > 用户管理 > 指派用户角色</div>
    <div class="button_bar">
        <button class="common_button" onclick="help('');">帮助</button>
        <button class="common_button" onclick="back();">返回</button>
        <button class="common_button" @click="updaterole();">保存</button>
    </div>
    <table class="query_form_table">
        <tr>
            <th>编号</th>
            <td>
                <input type="text" v-model="usr.usr_id" size="20"  readonly="readonly">
            </td>
            <th>用户名</th>
            <td>
                <input type="text" v-model="usr.usr_name" size="20"  readonly="readonly">
            </td>
        </tr>
        <tr>
            <th>
                角色
            </th>
            <td>
                <select v-model="usr.role_id">
                    <option value="" selected>未指派</option>
                    <option v-for="l in rolelist" :value="l.role_id">{{l.role_name}}</option>
                </select>
            </td>
            <th>
                状态
            </th>
            <td>
                <span v-if="usr.usr_flag==1">正常</span>
                <span v-if="usr.usr_flag==0">禁止</span>
            </td>
        </tr>
    </table>
</div>
</body>
<script>
    var app = new Vue({
        el: "#query",
        data: {
            usr: {
                usr_id: '',
                usr_name: '',
                usr_flag: '',
                role_id: '',
            },
            rolelist:[],
        },
        methods:{
            updaterole(){
                $.getJSON("/updaterole",{"id":this.usr.usr_id,"value":this.usr.role_id},function (json) {
                    if(json.code==200){
                        alert("指派成功！！");
                        location='list.html';
                    }else {
                        alert('服務器異常！！');
                    }
                });
            }
        },
        created() {
            let id = sessionStorage.getItem("id");
            $.getJSON("/querySysUserById2/" + id, function (json) {
                //  alert(JSON.stringify(json));
                app.usr = json.data.obj[0];
                if(app.usr.role_id==undefined){
                    app.usr.role_id="";
                }
            });

            $.getJSON("/queryrole",function (json) {
               app.rolelist=json.data.list;
            });
        }
    })
</script>
</html>
 
